
#ifndef   __STRING_LIB
#define   __STRING_LIB

#define   TYPE_BYTE			1
#define   TYPE_INTEGER		2
#define   TYPE_LONG			4

/* ERRORS */
extern int errno;
enum
{
	NO_ERR,
	NO_NUMBER 
};
	
//unsigned char StrCmp ( const unsigned char *s1, const unsigned char *s2 );   
int StrCmp(register const char * s1, register const char * s2);
unsigned char* MemCpy ( unsigned char *m1, unsigned char *m2, unsigned char ByteNumber );
unsigned char* StrCpy ( unsigned char *s1, const char *s2 );
void MemSet ( unsigned char *m, unsigned char ByteNumber, unsigned char FillByte );
//unsigned char MemCmp ( const unsigned char *s1, unsigned char *s2, unsigned char BytesNumber );
int MemCmp ( unsigned char* s1, unsigned char* s2, unsigned char BytesNumber );
long StrToLong( const char* s );
char* LongToStr( unsigned char* s, unsigned long Val );
char* ByteToStr_10( unsigned char* s, unsigned long Val  );
/* Lond with point. Example: Val=12 -> 0.12; Val = 309 -> 3.09; Val = 234789 -> 2347.89*/
char* Long_pToStr( unsigned char* s, unsigned long Val );


/* return length of string. If length > 512 return ERROR: ( -1) */
int StrLen( const char *s );

void Int_BCD_ToStr( unsigned char *s, unsigned int Integer );
unsigned int StrTo_Int_BCD( unsigned char *s );
unsigned char* StrCat(  unsigned char* to, const unsigned char* from );
unsigned char* StrnCat(unsigned char* to, const unsigned char* from, unsigned char size);
unsigned long StrToBCD_Long( unsigned char* Str );
/* return index of first found NUMBER. Example: "ABCD 2345Sa" return: 5 */
int StrFindToken_Number ( unsigned char* Str );
unsigned char* BCD_ToStr( unsigned char* Str, unsigned long BCD );

/* return number of Str bytes (digit of BCD) */
//unsigned char StrToBCD_Long( unsigned char* Str_BCD, unsigned char* Str );


unsigned char* StrCpy_UpTo_Ch ( unsigned char *s1, const char *s2, unsigned char Ch );
char* StrCat_UpTo_Ch(  char* to, const char* from, unsigned char Ch );

//int FindChar ( unsigned char* Str, unsigned char Ch );
unsigned char* FindChar ( unsigned char* Str, unsigned char Ch );

// /* return: offset of next Position after the Char; Number - Char by order */
// int FindCharNumber ( unsigned char* Str, unsigned char Ch, unsigned char Number );

/* return: pointer of the Char position; in errno will be offset of the Char */
unsigned char* FindCharNumber ( unsigned char* Str, unsigned char Ch, unsigned char Number );

/* find the char and set end of line token ('0') on the char place */
int StrReplaceChar ( unsigned char* Str, unsigned char Ch, unsigned char Replace ) ;
/* return: how many characters was replaced */
int StrReplaceCharAll ( unsigned char* Str, unsigned char Ch, unsigned char Replace );

unsigned char* CharToHex( unsigned char* Hex, unsigned char* Char );
unsigned char* CharnToHex( unsigned char* Hex, unsigned char* Char, unsigned char ByteCount );

unsigned char* HexToChar( unsigned char* Char, unsigned char* Hex, unsigned char HexCount );

unsigned char* StrToBCD ( unsigned char* Str_BCD, unsigned char* Str, unsigned char Str_BCD_Len );
unsigned char* BCDToStr( unsigned char* Char, unsigned char* BCD, unsigned char BCDCount );
extern bit PREFIX_EDIT;

/* Check if each element == Ch */
unsigned char Str_If_All_Set( unsigned char* Str, unsigned char Ch );

void FlipFlopN ( unsigned char* Str, unsigned char Len );
void FlipFlop ( unsigned char* Str );
void FlipFlopByte ( unsigned char* Byte );

unsigned char* StrCutBetweenChars( unsigned char* Destination, unsigned char* Source, unsigned char Char );
	
#define   ClearBuffer(b,ByteNumber) 	MemSet(b, ByteNumber, 0)	

char isupper( char c );
char isalpha( char c );
char isspace( char c );
char isdigit( char c );
char StrIsPrintableChar ( char Char );

#endif

